<template>
  <div class="header">
    <div class="wapper">
      <div class="left">
        <div class="icon"  @click="open = !open">
          <el-icon v-if="open"  size="30" color="#909399">
            <Close />
          </el-icon>
          <el-icon v-else  size="26" color="#909399">
            <Operation/>
          </el-icon>

        </div>
        <div class="menus" :style="{flex: open ? 1: 0}">
          <div class="menu-item" :class="[index == currentIndex ? 'active': '']" v-for="(item, index) in menus" @click="menuHandel(index)">{{item.name}}</div>
        </div>
      </div>
      <div class="right">
        <div @click="toUserInfo">个人中心</div>
        <div @click="handleLogout">退出</div>
      </div>
    </div>
  </div>
</template>
<script setup>
import {defineProps, ref} from 'vue'
import { useLogout } from '/@/components/hzsystem/LoginPublicFuncation';
import {useRouter} from "vue-router";

const router = useRouter()

const { handleLogout } = useLogout()


const toUserInfo = () => {
  router.push({name: 'UserInfo'})
}

const props = defineProps({
  menus: {
    type: Array,
    default: () => []
  }
})
const open = ref(false)

const currentIndex = ref(0)
const menuHandel = index => {
  currentIndex.value = index;
  router.push({path: props.menus[index].path})
}
</script>
<style scoped lang="scss">

.flex-aic{
  display: flex;
  align-items: center;
}

.menu-item-active{
  background-color: #f46246;
  color: #fff;
}

.header{
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  height: 50px;
  padding: 0 8px;
  box-shadow: 0 1px 4px rgba(0,21,41,.08);
  cursor: pointer;
  .wapper{
    @extend .flex-aic;
    justify-content: space-between;
    height: 50px;
    .left{
      @extend .flex-aic;
      .icon{
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: 1px solid #ccc;
        @extend .flex-aic;
        justify-content: center;
        margin-right: 8px;
        &:hover{
          background-color: #eee;
        }
      }
      .menus{
        @extend .flex-aic;
        overflow: hidden;
        transition: all 0.3s;
        .menu-item{
          @extend .flex-aic;
          justify-content: center;
          overflow: hidden;
          font-size: 14px;
          color: #333;
          height: 30px;
          width: 90px;
          margin-right: 8px;
          padding: 0 8px;
          border-radius: 15px;
          &:hover{
            @extend .menu-item-active;
          }
          transition: all 0.5s;
        }
        .active{
          @extend .menu-item-active;
          color: #fff;
        }
      }
    }

    .right{
      @extend .flex-aic;
      div {
        margin-right: 8px;
        font-size: 14px;
        color: #333;
        &:hover{
          color: #f46246;
        }
      }
    }
  }
}
</style>